import { DeployTaskListResultModel, RenewalAppParams, TaskQueryParams } from './model/deployTaskModel';
import { deployHttp } from '/@/utils/http/axios';
import { AppTemplateResp } from '../operation-center/common/model/commonModel';

enum Api {
  DEPLOY_TASK_DISPLAY_LIST = '/v1/job/list',

  DEPLOY_TASK_RETRY = '/v1/rollBack/job',

  DB_ROLLBACK = '/v1/rollBack/db',
  NS_ROLLBACK = '/v1/rollBack/ns',
  CONFIG_ROLLBACK = '/v1/rollBack/config',
  RELEASE_APP = '/v1/resource/release',
  RENEWAL_APP = '/v1/resource/renew',
  GET_TENANT_SIDE_APPS = '/v1/app/tenantSideApps',
  GET_DB_SELECT_LIST = '/v1/instance/getDbMultiTenantMode',
  GET_APP_SELECT_LIST = '/v1/instance/getAppMultiTenantMode',
}

export const getDeployTaskListByPage = (params: TaskQueryParams) => {
  return deployHttp.get<DeployTaskListResultModel>({
    url: Api.DEPLOY_TASK_DISPLAY_LIST,
    params,
  });
};

export const releaseApp = (data: { tenantCode: string; appId: string }) => {
  return deployHttp.post<string[]>({ url: Api.RELEASE_APP, data });
};

export const getTenantSideApps = (param?: any) => {
  let params1 = '';
  if (param && param.length != 0) {
    param.forEach((item) => {
      params1 += 'types=' + item + '&';
    });
  }
  return deployHttp.get<AppTemplateResp[]>({ url: Api.GET_TENANT_SIDE_APPS + '?' + params1 });
};
export const renewApp = (params: RenewalAppParams) => {
  return deployHttp.post<string>({ url: Api.RENEWAL_APP, params });
};

export const getDbMultiTenantMode = () => {
  return deployHttp.get<any[]>({ url: Api.GET_DB_SELECT_LIST });
};
export const getAppMultiTenantMode = () => {
  return deployHttp.get<any[]>({ url: Api.GET_APP_SELECT_LIST });
};
